<?php
// Originally written by xellisx
function parse_query($var)
{
  /**
   *  Use this function to parse out the query array element from
   *  the output of parse_url().
   */
  $var  = parse_url($var, PHP_URL_QUERY);
  $var  = html_entity_decode($var);
  $var  = explode('&', $var);
  $arr  = array();

  foreach($var as $val)
   {
    $x          = explode('=', $val);
    $arr[$x[0]] = $x[1];
   }
  unset($val, $x, $var);
  return $arr;
}


$str = 'http://android.api.iyuedan.com/api1.0/sign/up?udid=860311027410455&version=1.2.1&client=android&device=MI%203&appname=yuedan&market=xiaomi&lan=zh_cn&lat=44.336226&lng=84.92594?udid=860311027410455&version=1.2.1&client=android&device=MI+3&appname=yuedan&market=xiaomi&lan=zh_cn&lat=44.336226&lng=84.92594&birthday=1987-05-02&username=%F0%9F%94%A5%E8%8A%B1%E7%81%AB%F0%9F%94%A5&mobile=15299329870&password=li420520&checktoken=fa415a26e15cc757cc63a37454df97e6&sex=0&ver=1.0&%3Cver%3A%5B0-9%5D=';

$arr = parse_query($str);

var_dump($arr);

echo urldecode($arr['username']);

$array = array(
    "type" => "welcome",
    "message" => "Hello World!"
);
echo urldecode(http_build_query($array, '', ';'));
